package com.just_bean;

import com.just_bean.core.JustBean;
import com.just_bean.core.bean.BaseBean;
import com.just_bean.core.exception.BeanInitException;
import com.just_bean.core.exception.BeanScanException;
import com.just_bean.core.handler.AnnoHandler;

import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Map;

public class JustBeanApplication {
    private JustBean justBean = new JustBean();

    private JustBeanApplication() {
    }

    // 没有组件的空justBean
    public static JustBeanApplication emptyApp(Class<?> accessClz,
                                               Map<Class<? extends Annotation>, AnnoHandler> handlerMap,
                                               Map<Class<? extends Annotation>, Class<? extends BaseBean>> beanClzMap) throws BeanScanException, BeanInitException {
        JustBean justBean = new JustBean();
        // 注册组件
        justBean.register(handlerMap, beanClzMap);
        // 开始扫描
        justBean.scan(accessClz);

        JustBeanApplication justBeanApplication = new JustBeanApplication();
        justBeanApplication.justBean = justBean;
        return justBeanApplication;
    }

    public <T> T get(Class<T> clz, Object... cond) throws Exception {
        return this.justBean.get(clz, cond);
    }

    // 获取被该注解修饰过的实例
    public List<? extends BaseBean> listBeanWithAnnotation(Class<? extends Annotation> annotationClz) {
        return this.justBean.listBeanWithAnnotation(annotationClz);
    }

}
